package com.nanbei.eduService.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nanbei.eduService.entity.EduComment;
import com.nanbei.eduService.mapper.EduCommentMapper;
import com.nanbei.eduService.service.EduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-01-26
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public HashMap findCommentByCourseId(String courseId, long current, long limit) {

        Page<EduComment> eduCommentPage = new Page<>(current,limit);

        QueryWrapper<EduComment> eduCommentQueryWrapper = new QueryWrapper<>();
        eduCommentQueryWrapper.eq("course_id",courseId);
        this.baseMapper.selectPage(eduCommentPage,eduCommentQueryWrapper);
        //返回总记录数
        long total = eduCommentPage.getTotal();

        //数据List集合
        List<EduComment> records = eduCommentPage.getRecords();
        HashMap hashMap = new HashMap<>();
        hashMap.put("total",total);
        hashMap.put("records",records);
        return hashMap;
    }
}
